Colour palettes comes from http://soliton.vm.bytemark.co.uk/pub/cpt-city/index.html
Currently there are 7140 colour gradients. To se the names type cpt_names.
There are three functions:
find_cpt: To search the name of the colour gradient.Example:
library(cptcity)
find_cpt("radar")
[1] "idv_radar_dbz_nws" "idv_radar_dbz" "idv_radar_reflect_24" "idv_radar_topo_mdr"
[5] "ncl_radar_1" "ncl_radar"
# try find_cpt("rain")
cpt: To return the colour gradient.cptcity::cpt(pal = "ncl_radar_1", n = 100)
[1] "#B2F8FF" "#B2F8FF" "#B2F8FF" "#B2DCFF" "#B2BEFF" "#B2B8FF"
[7] "#B2B8FF" "#A088EE" "#8742D7" "#7D25CD" "#7D25CD" "#7322BE"
[13] "#601D9E" "#541A8B" "#541A8B" "#66328A" "#AF9387" "#EDE685"
[19] "#EDE685" "#ECE584" "#DDD67C" "#CDC673" "#CDC673" "#CDC673"
[25] "#B7B380" "#9D9C91" "#969696" "#969696" "#B4B4B4" "#E6E6E6"
[31] "#FFFFFF" "#FFFFFF" "#EEFFFF" "#C6FFFF" "#AAFFFF" "#AAFFFF"
[37] "#A2F6FF" "#79C9FF" "#55A0FF" "#55A0FF" "#55A0FF" "#3A55FF"
[43] "#2009FF" "#1D00FF" "#1D00FF" "#4053C3" "#6EBF75" "#7EE55B"
[49] "#7EE55B" "#71DE54" "#5AD249" "#4ECC43" "#4ECC43" "#48C741"
[55] "#39BB3C" "#2EB239" "#2EB239" "#2DB039" "#25A43B" "#1E993D"
[61] "#1E993D" "#1E993D" "#7FC54E" "#EAF562" "#FFFF66" "#FFFF66"
[67] "#FFED66" "#FFD566" "#FFCC66" "#FFCC66" "#FFBC5F" "#FF9B53"
[73] "#FF884C" "#FF884C" "#FF7945" "#FF442D" "#FF1919" "#FF1919"
[79] "#FD1A1A" "#E52B2B" "#CD3C3C" "#CC3D3D" "#CC3D3D" "#BC3838"
[85] "#A93232" "#A53131" "#A53131" "#BA2269" "#DD0AC3" "#ED00ED"
[91] "#ED00ED" "#D814E6" "#A945D7" "#8967CD" "#8967CD" "#9474CF"
[97] "#CAB5DB" "#FAF0E6" "#FAF0E6" "#FAF0E6"
lucky: To choose a random colour gradientcptcity::lucky(n = 100)
Colour gradient: occ_2_occ093, number: 6450
[1] "#FF754C" "#FE764D" "#FE774E" "#FE794F" "#FE7A50" "#FE7B52"
[7] "#FE7D53" "#FE7E54" "#FE7F55" "#FE8157" "#FE8258" "#FE8359"
[13] "#FE855A" "#FE865C" "#FE875D" "#FE895E" "#FE8A5F" "#FD8B60"
[19] "#FD8D62" "#FD8E63" "#FD8F64" "#FD9165" "#FD9267" "#FD9368"
[25] "#FD9569" "#FD966A" "#FD976C" "#FD996D" "#FD9A6E" "#FD9B6F"
[31] "#FD9D70" "#FD9E72" "#FD9F73" "#FDA174" "#FCA275" "#FCA377"
[37] "#FCA578" "#FCA679" "#FCA77A" "#FCA97C" "#FCAA7D" "#FCAB7E"
[43] "#FCAD7F" "#FCAE80" "#FCAF82" "#FCB183" "#FCB284" "#FCB385"
[49] "#FCB587" "#FCB688" "#FCB789" "#FCB88A" "#FCB98B" "#FCB98C"
[55] "#FCBA8D" "#FCBB8E" "#FCBC8F" "#FCBD8F" "#FCBE90" "#FCBE91"
[61] "#FCBF92" "#FCC093" "#FCC194" "#FCC295" "#FCC396" "#FCC397"
[67] "#FCC498" "#FCC599" "#FCC69A" "#FCC79B" "#FCC79C" "#FCC89C"
[73] "#FCC99D" "#FCCA9E" "#FCCB9F" "#FCCCA0" "#FCCCA1" "#FCCDA2"
[79] "#FCCEA3" "#FCCFA4" "#FCD0A5" "#FCD1A6" "#FCD1A7" "#FCD2A8"
[85] "#FCD3A9" "#FCD4A9" "#FCD5AA" "#FCD6AB" "#FCD6AC" "#FCD7AD"
[91] "#FCD8AE" "#FCD9AF" "#FCDAB0" "#FCDBB1" "#FCDBB2" "#FCDCB3"
[97] "#FCDDB4" "#FCDEB5" "#FCDFB6" "#FDE0B7"
# install.packages("cptcity") 1.0.0
# devtools::install_github("ibarraespinosa/cptcity") 1.0.2
library(cptcity)
image(matrix(1:100), col = cpt(pal = "mpl_inferno"))
And you can use it ggplot2
library(cptcity)
library(ggplot2)
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density))
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density)) +
scale_fill_gradientn(colours = cpt(n = 100))
or raster
library(cptcity)
library(raster)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
spplot(r, scales = list(draw = T))
spplot(r, scales = list(draw = T),
col.regions = rev(cpt(n = 100, pal = "colo_Skyblue2u_Gentle_Waves")))
or sf
library(cptcity)
library(sf)
f = st_read(system.file("shapes/", package="maptools"), "sids")
st_crs(f) <- 4326
plot(f["AREA"], pal = cpt(colorRampPalette = T))
or mapview
library(cptcity)
library(mapview)
library(sf)
f = st_read(system.file("shapes/", package="maptools"), "sids", crs = 4326)
mapview(f, zcol = "AREA", col.regions = cpt(colorRampPalette = T), legend = T)
# install.packages("cptcity") 1.0.0
# devtools::install_github("ibarraespinosa/cptcity") 1.0.1
library(cptcity)
image(matrix(1:100), col = lucky())
Each palette has a COPYING.XML files available at ins/extdata. To see each file do:
library(cptcity)
files <- list.files(system.file("extdata",
package = "cptcity"),
pattern = ".xml",
recursive = T,
full.names = T)
# For instance, the COPYING files of "arendal" is
files[1]
# and the file
readLines(files[1])
1] "/usr/local/lib/R/site-library/cptcity/extdata/arendal/COPYING.xml"
[1] "<?xml version=\"1.0\"?>"
[2] "<copying>"
[3] " <authors>"
[4] " <author href=\"http://www.grida.no/graphicslib/\">"
[5] " <name>GRID-Arendal</name>"
[6] " </author>"
[7] " </authors>"
[8] " <license>"
[9] " <informal>"
[10] " Attribution and linkback requested."
[11] " </informal>"
[12] " <year>2014</year>"
[13] " <text>"
[14] " Using this graphic and referring to it is encouraged, "
[15] " and please use it in presentations, web pages, newspapers, "
[16] " blogs and reports."
[17] ""
[18] " For any form of publication, please include the link to "
[19] " this page and give the cartographer/designer credit."
[20] " </text>"
[21] " </license>"
[22] " <src>"
[23] " <format>PNG images</format>"
[24] " <link href=\"http://www.grida.no/graphicslib/detail/mean-surface-temperature_c7e4\""
[25] "\t >Temperature</link>"
[26] " <link href=\"http://www.grida.no/graphicslib/detail/arctic-topography-and-bathymetry_5645\""
[27] "\t >Arctic bathymetry</link>"
[28] " <link href=\"http://www.grida.no/graphicslib/detail/map-of-zimbabwe_36a5\""
[29] "\t >Zambezi</link>"
[30] " </src>"
[31] " <distribute>"
[32] " <qgis distribute=\"yes\" license=\"other\"/>"
[33] " </distribute>"
[34] "</copying>"